#include <stdio.h>
#include <math.h>

// arr为a0, a1, ... an,
// size为arr元素个数
// k为常数
double simple(double arr[], int size, double k) {
    double ret = 0.0;
    int i = 0;
    for (i = 0; i < size; i++) {
        ret += arr[i] * pow(k, i); // a_i * x^i
    }
    return ret;
}

double qinjiushao(double arr[], int size, double k) {
    double ret = arr[size - 1]; // a_n
    int i;
    for (i = size - 1; i > 0; i--) {
        ret = ret * k + arr[i - 1]; // a_n * x + a_{n-1}
    }
    return ret;
}

int main(int argc, char const *argv[])
{
    // f(x) = 1 + x^10
    double arr[] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
    int size = sizeof(arr) / sizeof(double);
    const double k = 2;
    printf("%f\n", simple(arr, size, k));
    printf("%f\n", qinjiushao(arr, size, k));
    return 0;
}
